package com.example.a02back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.a02back.entity.FavoriteItem;
import com.example.a02back.entity.FavoriteTopic;
import com.example.a02back.mapper.FavoriteTopicMapper;
import com.example.a02back.service.IFavoriteTopicService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author SimpChaos
 * @since 2022-07-15
 */
@Service
public class FavoriteTopicServiceImpl extends ServiceImpl<FavoriteTopicMapper, FavoriteTopic> implements IFavoriteTopicService {

    public String addfavoriteTopic(String uid,String topicid){
        FavoriteTopic a = new FavoriteTopic();
        a.setUid(uid);
        a.setTopicid(topicid);
        LambdaQueryWrapper<FavoriteTopic> wrapper = new LambdaQueryWrapper<>();
        if(this.getOne(wrapper) == null)     return String.valueOf(this.save(a));
        else return "have already favorite";
    }

    public List<String> getFavTopic(Long decode,String uid){
        Page<FavoriteTopic> Page = new Page<>(decode,10);
        LambdaQueryWrapper<FavoriteTopic> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(FavoriteTopic::getUid,uid);
        List<FavoriteTopic> list = this.page(Page,wrapper).getRecords();
        List<String> result = new ArrayList<>();
        for(FavoriteTopic f:list){
            result.add(f.getTopicid());
        }
        return result;
    }



}
